package com.yuandian.customer.perception.controller;

import com.yuandian.api.customer_perception.po.LowFrequenceSystemParams;
import com.yuandian.api.customer_perception.po.LowFrequencyHistoryExportParams;
import com.yuandian.api.customer_perception.po.LowFrequencyOverviewParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.data.resolver.ParamResolver;
import com.yuandian.constant.ConfigKey;
import com.yuandian.customer.perception.service.IHisExportListService;
import com.yuandian.utils.PageDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 说明：历史导出列表controller
 * @Author yanjun
 * @Date 2021年4月14日 下午3:26:30
 */
@RestController
@RequestMapping("/lowfrequency/hisexportlist")
public class HisExportListController {

	@Autowired
	private IHisExportListService hisExportListService;


	/**
	 * 查询历史导出文件记录列表
	 * @param params 低频受理业务概况请求对象
	 * @return 通用分页对象
	 */
	@RequestMapping(value = "/getHisFileList", method = RequestMethod.POST)
	public R list(@RequestBody LowFrequencyHistoryExportParams params) {
		PageDataInfo info = hisExportListService.queryHisExportList(params);
		return R.ok(info);
	}

	/**
	 * 根据id导出历史导出记录列表(pdf)
	 * @param params 低频受理业务概况请求对象
	 * @return 通用返回对象
	 */
	@RequestMapping(value = "/exportByIds", method = RequestMethod.POST)
	public R exportByIds(@RequestBody LowFrequencyOverviewParams params) {
		return hisExportListService.exportHisExportListByIds(params);
	}

	/**
	 * 导出历史导出记录列表(pdf)
	 * @param params 低频受理业务概况请求对象
	 * @return 通用返回对象
	 */
	@RequestMapping(value = "/export", method = RequestMethod.POST)
	public R export(@RequestBody LowFrequencyOverviewParams params) {
		return hisExportListService.exportHisExportList(params);
	}

	/**
	 * 从历史导出表下载文件（压缩包形式）(new-20210628)
	 *
	 * @param params 低频受理业务概况请求对象
	 */
	@RequestMapping(value = "/downLoadHistoryFileZip", method = RequestMethod.POST)
	public void downLoadHistoryFileZip(@RequestBody LowFrequencyHistoryExportParams params, HttpServletResponse response) {
		String dpslFlieExportRoute = ParamResolver.getStr(ConfigKey.DPSL_FILE_PATH);
		hisExportListService.downLoadHistoryFileZip(params,dpslFlieExportRoute, response);
	}

	/**
	 * 一键导出历史导出记录列表(新)(PDF)
	 *
	 * @param params 低频受理业务概况请求对象
	 * @return 通用返回对象
	 */
	@RequestMapping(value = "/exportNew", method = RequestMethod.POST)
	public R exportNew(@RequestBody LowFrequenceSystemParams params) {
		if (params.getType() == null || params.getCycleTimeUsec() == null || params.getStartTime() == null || params.getEndTime() == null) {
			return R.failed("请求参数出错");
		}
		return hisExportListService.exportHisExportListNew(params);
	}


	/**
	 * 从历史导出表下载文件（PDF 形式）(new-20210628)
	 *
	 * @param fileName 文件名
	 */
	@RequestMapping(value = "/downLoadHistoryPdfFile", method = RequestMethod.POST)
	public void downLoadHistoryPdfFile(@RequestBody String fileName, HttpServletResponse response) {
		hisExportListService.downLoadHistoryPdfFile(fileName, response);
	}


}
